package com.com.itext.day4;

import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.kernel.color.Color;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.*;
import com.itextpdf.kernel.pdf.action.PdfAction;
import com.itextpdf.kernel.pdf.annot.PdfAnnotation;
import com.itextpdf.kernel.pdf.annot.PdfLineAnnotation;
import com.itextpdf.kernel.pdf.annot.PdfLinkAnnotation;
import com.itextpdf.kernel.pdf.annot.PdfTextAnnotation;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Link;
import com.itextpdf.layout.element.Paragraph;

import java.io.FileNotFoundException;

import static com.sun.org.apache.xml.internal.serialize.LineSeparator.Windows;

public class demo2 {
    public static void main(String[] args) throws Exception {
       // PdfWriter writer = new PdfWriter("D:\\测试pdf\\day4_2_1.pdf");
       /* PdfDocument pdf = new PdfDocument(writer);
        Document doc = new Document(pdf);
        PdfLinkAnnotation pdfLink = new PdfLinkAnnotation(new Rectangle(0,0))
                .setAction(PdfAction.createURI("http://itextpdf.com/"));
        Link link = new Link("hree",pdfLink);
        Paragraph p = new Paragraph("this id a text ")
                .add(link.setUnderline())
                .add("over   ");
        doc.add(p);
        doc.close();*/
        PdfDocument pdf = new PdfDocument(new PdfWriter("D:\\测试pdf\\day4_2_2.pdf"));
        PdfPage page = pdf.addNewPage();
        PdfArray lineEndings = new PdfArray();
        lineEndings.add(new PdfName("Diamond"));
        lineEndings.add(new PdfName("Diamond"));
        PdfAnnotation annotation = new PdfLineAnnotation(
                new Rectangle(0, 0),
                new float[]{20, 790, page.getPageSize().getWidth() - 20, 790})
                .setLineEndingStyles((lineEndings))
                .setContentsAsCaption(true)
                .setTitle(new PdfString("iText"))
                .setContents("The example of line annotation")
                .setColor(Color.BLUE);
        page.addAnnotation(annotation);
        pdf.close();
    }
}
